package b2.widget.guide
{
	import b2.net.*;
	import b2.util.*;
	import b2.scene.guide.*;
	import b2.widget.BasicButton;
	
	import flash.display.Sprite;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;
	
	public class GuideMessageBox extends Sprite
	{
		public function GuideMessageBox(name:String, message:String, hasOKButton:Boolean = false, hasShareButton:Boolean = false, alpha:Number = 1)
		{
			super();
			var GuideMessageBgr:Class = ResourceHelper.getInstance().getClassByName("GuideMessageBgr");
			var mainSprite:Sprite = new GuideMessageBgr();
			mainSprite.alpha = alpha;
			addChild(mainSprite);
			
			//参谋美女
			var Alice:Class = ResourceHelper.getInstance().getClassByName("Alice");
			var alice:Sprite = new Alice();
			alice.height = 350;
			alice.scaleX = alice.scaleY;
			alice.x = 230;
			alice.y = -100;
			addChild(alice);

			//名字
			var titleText:TextField = new TextField();
			titleText.selectable = false;
        	titleText.autoSize = TextFieldAutoSize.CENTER;
			titleText.defaultTextFormat = new TextFormat("微软雅黑", 18, 0x000000);
			titleText.filters = [new GlowFilter(0xFFFFFF, 1, 3, 3, 10, BitmapFilterQuality.HIGH)];
			titleText.htmlText = name;
			titleText.x = 20;
			titleText.y = 20;
			addChild(titleText);
			
			//信息文字
			var messageText:TextField = new TextField();
			messageText.selectable = false;
        	messageText.autoSize = TextFieldAutoSize.LEFT;
        	messageText.wordWrap = true;
        	messageText.width = 260;
			messageText.defaultTextFormat = new TextFormat("微软雅黑", 16, 0x000000);;
			messageText.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			messageText.htmlText = message;
			messageText.x = 20;
			messageText.y = 50;
			addChild(messageText);
			
			if (hasShareButton)
			{
				//分享按钮
				var ButtonBgr:Class = ResourceHelper.getInstance().getClassByName("ButtonBgr0");
				var buttonShare:BasicButton = new BasicButton(ButtonBgr, "分享");
				buttonShare.x = (mainSprite.width  - buttonShare.width) / 4;
				buttonShare.y = mainSprite.height - buttonShare.height - 20;
				buttonShare.addEventListener(MouseEvent.CLICK, onButtonShareClick);
				addChild(buttonShare);
				//关闭按钮
				var ButtonCls:Class = ResourceHelper.getInstance().getClassByName("ButtonBgr0");
				var buttonClose:BasicButton = new BasicButton(ButtonCls, "取消");
				buttonClose.x = (mainSprite.width  - buttonClose.width) * 3 / 4;
				buttonClose.y = mainSprite.height - buttonClose.height - 20;
				buttonClose.addEventListener(MouseEvent.CLICK, onButtonOKClick);
				addChild(buttonClose);
			}
			else if (hasOKButton)
			{
				//确定按钮
				ButtonBgr = ResourceHelper.getInstance().getClassByName("ButtonBgr0");
				var buttonOK:BasicButton = new BasicButton(ButtonBgr, "确定");
				buttonOK.x = (mainSprite.width  - buttonOK.width) / 2;
				buttonOK.y = mainSprite.height - buttonOK.height - 20;
				buttonOK.addEventListener(MouseEvent.CLICK, onButtonOKClick);
				addChild(buttonOK);
			}
		}
		
		//点击分享
		private function onButtonShareClick(event:MouseEvent):void
		{
			RRApiHelper.sendFeed("完成了坦克要塞新兵训练");
			GuideScene.getInstance().step++;
			close();
		}
		
		//点击确定
		private function onButtonOKClick(event:MouseEvent):void
		{
			GuideScene.getInstance().step++;
			close();
		}
		
		public function close():void
        {
        	if (this.parent != null)
        	{
        		this.parent.removeChild(this);
        	}
        }
        
	}
}